
module Test.Utils(strictToLazy,lazyToStrict) where

import qualified Data.ByteString as B

import qualified Data.ByteString.Lazy as L

-- Break ByteString to pieces of 48 kbytes
breakdown :: B.ByteString -> Int -> [B.ByteString]
breakdown bs n
        | B.null bs = []
        | otherwise = bhead : btail
        where   bhead = B.take n bs
                btail = breakdown (B.drop n bs) n

-- Strict ByteString to lazy one, straight as it is
strictToLazy :: B.ByteString -> L.ByteString
strictToLazy strict = 
        L.fromChunks $ breakdown strict (48*1024) 

-- Lazy ByteString to strict one
lazyToStrict :: L.ByteString -> B.ByteString
lazyToStrict lazy = B.concat $ L.toChunks lazy
